package com.amigo.online.provider.manager.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.amigo.online.common.base.controller.BaseController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.provider.manager.model.entity.HobbyTbl;
import com.amigo.online.provider.manager.service.HobbyTblService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@RestController
@RequestMapping(value = "/hobbyTbl", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class HobbyTblController extends BaseController {

    @Resource
    private HobbyTblService hobbyTblService;

    @PostMapping(value = "/gethobbyTblList")
    public ResponseEntity<Response> gethobbyTblList(@RequestBody HobbyTbl hobbyTbl) {

        JSONObject result = new JSONObject();
        // 分页语句
        Page<Object> page = PageHelper.startPage(hobbyTbl.getPageNo(), 10);
        List<HobbyTbl> hobbylist = hobbyTblService.findHobbyTblList(hobbyTbl);
        result.put("hobbylist", hobbylist);
        result.put("pagetotal", page.getTotal());
        return success(result);
    }

    @PostMapping(value = "/savehobbyTbl")
    public ResponseEntity<Response> savehobbyTbl(@RequestBody HobbyTbl hobbyTbl) {
        return success(hobbyTblService.saveHobbyTbl(hobbyTbl));
    }

    @PutMapping(value = "/updatehobbyTbl")
    public ResponseEntity<Response> updatehobbyTbl(@RequestBody HobbyTbl hobbyTbl) {
        return success(hobbyTblService.updateHobbyTbl(hobbyTbl));
    }

    @PutMapping(value = "/deletehobbyTbl")
    public ResponseEntity<Response> deletehobbyTbl(@RequestBody HobbyTbl hobbyTbl) {
        return success(hobbyTblService.deleteHobbyTbl(hobbyTbl));
    }

}
